/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.brainstretch.models.actions;

import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import org.brainstretch.models.quizzes.Answer;
import org.brainstretch.models.quizzes.Question;

/**
 *
 * @author mrodaitis
 */
@XmlRootElement
@Entity
public class UserAnswer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(nullable=false)
    private String text;

    @ManyToOne    
    private Question question;

    @Enumerated(EnumType.STRING)
    private AnswerStatus status;

    public UserAnswer() {
        status = AnswerStatus.NotSubmitted;
    }
    
    public UserAnswer(Question question, String answer){
        this();
        this.text = answer;
        this.question = question;
    }
    
    public Question getQuestion() {
        return question;
    }

    public void setQuestion(Question question) {
        this.question = question;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }   
    
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }

    public AnswerStatus getStatus() {
        return status;
    }

    public void setStatus(AnswerStatus status) {
        this.status = status;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Answer)) {
            return false;
        }
        UserAnswer other = (UserAnswer) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.brainstretch.models.actions.Answer[ id=" + id + " ]";
    }
    
}
